<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var images;
        function preloadimage(){
            images = new Array("eat.png","pig.png");
            for(var i = 0; i<images.length;i++){
                // new Image 创建图片对象，预加载图片（preloading image）
                var img = new Image();
                img.src = images[i];
            }
        }

        // onmouseover事件
        function over(index){
            document.images[index].src=images[index+1];
        }
         // onmouseout 事件
        function out(index){
            document.images[index-1].src=images[index-1];
        }
    </script>
</head>
<body onload="preloadimage()">
    <img src="eat.png" alt="" width="300" height="300" onmouseover="over(0)" onmouseout="out(1)">
</body>
</html>